package day3.service;

import day3.dao.AccountDao;
import day3.entity.Account;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

@Service
public class AccountServiceImpl {
    @Autowired
	AccountDao dao;

	@Transactional(rollbackFor = Exception.class,readOnly = true,timeout = 4)
	public void transfer(String from, String to, Double money)throws Exception {
		dao.update(from, 0-money);
		try {
			Thread.sleep(5000);
		} catch (InterruptedException e) {}

		dao.update(to, money);
//		throw new Exception("kkkkkkkkkkkkkkkkkkkkkkkk");
	}

	@Transactional(readOnly = true)
	public void query(String name) {
		System.out.println(name+"的余额："+dao.selectMoney(name));
	}


	@Transactional(isolation = Isolation.REPEATABLE_READ)
	public void insert() {
		System.out.println(dao.insert(new Account(null,"a2",500.0)));
	}
}